#include <bits/stdc++.h>
// 2025/04/04
// tag: 
// Author: Forever
using namespace std;
using int64 = int64_t;

int n, a[1001], dp[1001][1001];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        dp[i][i] = 1;
    for (int len = 2; len <= n; len++)
        for (int l = 1, r = len; r <= n; l++, r++){
            if (a[l] < a[l + 1])
                dp[r][l] += dp[r][l + 1];
            if (a[l] < a[r] && len != 2)
                dp[r][l] += dp[l + 1][r];
            if (a[r] > a[r - 1])
                dp[l][r] += dp[l][r - 1];
            if (a[r] > a[l] && len != 2)
                dp[l][r] += dp[r - 1][l];
            dp[l][r] %= 19650827;
            dp[r][l] %= 19650827;
        }
    cout << (dp[n][1] + dp[1][n]) % 19650827 << endl;
    return 0;
}